/**
 * @ author: 汪孟苹
 */
define(["jquery","bbcare",
    "scprit/followup/app/datatable/datatable.servers.js",
    "scprit/followup/app/datatable/datatable.ui.js",],function($,$bb,$datatableServers,$datatableUi){
	var servers = {};
	var URL = $bb.baseUrl("followup");
    /**
     * 请求队列
     */
    servers.ajaxQueue = function(callback){
        $bb.ajax({
            url: URL + "followup/service/queue/followQueueListQuery",
            success: function (data) {
                if(data.success){
                    callback(data.data.rows);
                }
            }
        });
    }
    /**
     * 入参
     */
    var inParams = function(args){
        var data = JSON.stringify({
            data: {
                "args": JSON.stringify(args),
                "patientName": $.trim($("#patientName").val()),
                "phoneNum": $.trim($("#phoneNum").val()),
                "hisNo": $.trim($("#hisNo").val()),
                "queueId": $("#queue").val(),
                "sendStatus": $("#sendStatus").val(),
                "qryStartTime": $("#timeFrom").val(),
                "qryEndTime": $("#timeTo").val(),
            }
        });
        return data;
    }
    /**
     * 出参
     */
    var outParams = function(data){
        return data.rows;
    }
    /**
     * columns
     */
    var columnsHisNo = function(e){
        return e.hisNo1 ? e.hisNo1 : e.hisNo2 ? e.hisNo2 : e.hisNo3 ? e.hisNo3 : "-";
    }
    var columnsPatientName = function(e){
        var imgSrc = 'page/followup/imgs/comm/';
        imgSrc += e.gender == 'F' ? 'girl.png' : 'boy.png';
        var h = '<img class="pic-sex" src='+imgSrc+'>';
            h += '<span class="patient-name">' + e.patientName + '</span>'; 
        return h;
    }
    var columnsData = function(){
        var columnsArr = [columnsHisNo,columnsPatientName,'phoneNum','birthday','followQueueName','taskName','sendTime','statusName','informName'];
        return $datatableServers.getColumnsData(columnsArr);
    }
    /**
     * 初始化完成之后的回调函数
     */
    var initComplete = function(setting,json){
        $("#followupWarnSendRecord").prev("div.row").remove();
        $("#serchBtn").click(function(){
            $datatableUi.table.api().ajax.reload();  // 出发dt的重新加载数据的方法
            var args = $datatableUi.table.api().ajax.params();   //获取dt请求参数
        });
        $("#resetBtn").click(function(){
            $("#patientName,#phoneNum,#hisNo,#queue,#timeFrom,#timeTo,#sendStatus").val("");
            $datatableUi.table.api().ajax.reload();  // 出发dt的重新加载数据的方法
            var args = $datatableUi.table.api().ajax.params();   //获取dt请求参数
        });
    }
    /**
     * 获取datatable里的options
     */
    servers.getOptions = function(){
        var sessionId = $bb.getSessionStorage("sessionId");
        var options = {
            "ajax": {
                "url": URL + "followup/service/patient/inform/ptInformRdQuery?sessionId=" + sessionId,
                "data": inParams,
                "dataSrc": outParams
            },
            "columns": columnsData(),
            "initComplete": initComplete,
        };
        return options;
    }

	return servers;
});